﻿window.initCanvas = function (canvasId) {
    const canvas = document.getElementById(canvasId);
    const context = canvas.getContext('2d');
    context.lineWidth = 2;
    context.lineCap = 'round';
    context.strokeStyle = 'black';

    // 清除Canvas（可选）  
    context.clearRect(0, 0, canvas.width, canvas.height);
};

window.drawPolyline = function (canvasId, points) {
    const canvas = document.getElementById(canvasId);
    const context = canvas.getContext('2d');

    // 清除之前的线（如果需要）  
    context.clearRect(0, 0, canvas.width, canvas.height);

    // 绘制新线  
    context.beginPath();
    context.moveTo(points[0][0], points[0][1]);
    for (let i = 1; i < points.length; i++) {
        context.lineTo(points[i][0], points[i][1]);
    }
    //context.lineTo(points[i][0], points[i][1]);
    context.stroke();
};